const deskItem = {
  state: {
    deskInfo: null,
    finalMenu: []
  },
  mutations: {
    PUT_DESK_INFO: function (state, deskInfo) {
      state.deskInfo = deskInfo
      sessionStorage.setItem('deskInfo', state.deskInfo)
    },
    PUT_FINAL_MENU: function (state, data) {
      state.finalMenu = data
    },
    CHANGE_FINAL_MENU: function (state, goodsId) {
      let checkIndex = state.finalMenu.indexOf(goodsId)
      if (checkIndex > -1) {
        // this.$alert('该产品已加入菜单', '提示', {
        //   confirmButtonText: '确定'
        // })
      } else {
        state.finalMenu.push(goodsId)
        sessionStorage.setItem('finalMenu', JSON.stringify(state.finalMenu))
      }
    },
    SPLICE_FINAL_MENU: function (state, index) {
      state.finalMenu.splice(index, 1)
      sessionStorage.setItem('finalMenu', JSON.stringify(state.finalMenu))
    }
  },
  getters: {
    getDeskInfo: function (state) {
      return state.deskInfo
    },
    getFinalMenu: function (state) {
      return state.finalMenu
    }
  },
  actions: {
    putDeskInfo ({ commit }, data) {
      commit('PUT_DESK_INFO', data)
    },
    changeFinalMenu ({ commit }, data) {
      commit('CHANGE_FINAL_MENU', data)
    },
    spliceFinalMenu ({ commit }, data) {
      commit('SPLICE_FINAL_MENU', data)
    },
    putFinalMenu ({ commit }, data) {
      commit('PUT_FINAL_MENU', data)
    }
  }
}
export default deskItem
